﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true"
    CodeBehind="news-list.aspx.cs" Inherits="VQWEB.administrator.news.news_list" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
 <div class="table-responsive">       
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
     <script type="text/javascript">
         ShowToolBar("add");
         var url_ashx = "/admin/news/handler";
         var url_list = '<%=ResolveUrl("~/administrator/templates/list.tpl") %>';
         $(document).ready(function () {
             $.get(url_ashx, { list_news: "list_news" }, function (data) {
                 list(data);
             });
         });

         $(document).on("click", "#btnAdd", function () {
             window.location = "/admin/news/add";
         });

         $(document).on("click", "#btnEdit", function () {
             var Id = $("input[name='chkItem']:checked").first().attr("value");
             if (Id != undefined)
                 window.location = "/admin/news/edit/" + Id;
         });
         //LockUnLock
         $(document).on("click", "#btnLockUnlock", function () {
             var array = InputChecked();
             if (array.length > 0) {
                 $.post(url_ashx, { lockunlock_news: JSON.stringify(array) }, function (data) {
                     list(data);
                 });
             }
         });
         //Delete
         $(document).on("click", "#btnDelete", function (e) {
             var array = InputChecked();
             if (array.length > 0) {
                 if (confirm("Bạn muốn xóa bản ghi không ???")) {
                     $.post(url_ashx, { delete_news: JSON.stringify(array) }, function (data) {
                         list(data);
                     });
                 }
             }

         });

         //List
         function list(data) {
             var plusData = $.parseJSON(data);
             var columns = ["STT", "<input name='chkAll' value='' type='checkbox'>", "Title", "Lượt xem","Vị trí", "Active"];
             var rows = new Array();
             $.each(plusData, function (i, obj) {
                 var row = [];
                 var ishome = (obj.ishome) ? "Trang chủ" : "Trang trong";
                 var active = (obj.active) ? "Kích hoạt" : "Chưa kích hoạt";
                 var url = "<a href=/admin/news/view/" + obj.id + ">" + obj.title + "</a>";
                 var checkbox = "<input name='chkItem' type='checkbox'  value=" + obj.id + ">";
                 row.push(i + 1);
                 row.push(checkbox);
                 row.push(url);
                 row.push(obj.hit);
                 row.push(ishome);
                 row.push(active);
                 rows.push(row);
             });
             $('div.table-responsive').empty();
             $.jqoteload(url_list, function (templates) {
                 $('div.table-responsive').jqoteapp(templates.list_tpl, { columns: columns, rows: rows });
             });
         }
    </script>
</asp:Content>
